//
//  EditRealNameViewController.m
//  JiuLe
//
//  Created by SunChao on 16/11/15.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "EditRealNameViewController.h"
#import "MallRequestManager.h"
@interface EditRealNameViewController ()
@property (nonatomic,strong)IBOutlet UITextField *textField;
@property (nonatomic,strong)IBOutlet UIButton *sureButton;
@end

@implementation EditRealNameViewController
- (IBAction)sureBtnAction:(UIButton *)sender
{
    if (self.textField.text==nil||[self.textField.text isEqualToString:@""]) {
        [SVProgressHUD showErrorWithStatus:@"请输入真实姓名"];
    }else{
        NSString *userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userID"];
        NSString *truename = self.textField.text;
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setObject:userId forKey:@"user_id"];
        [params setObject:truename forKey:@"truename"];
        [SVProgressHUD showWithStatus:@"加载中"];
        [MallRequestManager post:@"Personinfo/querytruename" RequestParams:params FinishBlock:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (connectionError) {
                [SVProgressHUD showErrorWithStatus:@"服务器请求错误"];
                return ;
            }
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            [SVProgressHUD dismiss];
            if ([[dic objectForKey:@"message"]isEqualToString:@"修改成功"]) {
                [self performSelectorOnMainThread:@selector(backTo) withObject:nil waitUntilDone:YES];
            }else
            {
                [SVProgressHUD showErrorWithStatus:[dic objectForKey:@"message"]];
            }
        }];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"修改真实姓名";
    [self showNavgationWithLeftItemWithTitle:@"返回"];
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.sureButton setBackgroundColor:RGB(59, 172, 237)];
    self.textField.text = self.name ;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 15;
   
}

@end
